﻿@model PagedList.IPagedList<AppsGenerator.Models.Application>
    @using PagedList.Mvc;
    <link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

    @{
        ViewBag.Title = "My Applications";
    }

                               <div class="col-lg-12">
                                   <h1 class="page-header">
                                       My Applications
                                   </h1>
                               </div>

    <form class="navbar-form" role="search">
        <div class="container">
            
            <div class="row">
                <div class="col-md-6">
                    <div id="custom-search-input">
                        <div class="input-group col-md-12">
                            <input type="text" id="search" name="search" class="form-control" placeholder="Search" />
                            <span class="input-group-btn">
                                <button class="btn btn-default" type="submit">
                                    <i class="glyphicon glyphicon-search"></i>
                                </button>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="col-md-2">
                    @Html.ActionLink("Create New", "Create", null, new { @class = "btn btn-primary" })
                </div>
            </div>
        </div>
    </form>

    <br />

    @if (Model.Count() > 0)
    {

        <table class="table table-striped">
            <tr>
                <th></th>
                <th>

                </th>
                <th>
                    @Html.DisplayNameFor(model => model.First().Name)
                </th>

                <th>
                    @Html.DisplayNameFor(model => model.First().url)
                </th>
                <th>Manage App</th>
                <th></th>
            </tr>

@{
        string Url = "";
}
            @foreach (var item in Model)
            {
                
                string css = (item.is_running.HasValue && item.is_running.Value) ? "btn btn-danger btn-xs" : "btn btn-success btn-xs";
                string btnIco = (item.is_running.HasValue && item.is_running.Value) ? "stop" : "play";
                <tr>
                    <td>
                        <button type="button" data-app-id="@item.Id" data-app-running="@item.is_running" class="@css btnStartStop">
                            <span class="glyphicon glyphicon-@btnIco"></span>
                        </button> 
                    </td>
                    <td>
                        <button type="button" data-app-id="@item.Id" class="btn btn-default btn-xs btnRestart">
                            <span class="glyphicon glyphicon-refresh"></span>
                        </button> 
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
                        @if(item.generated.HasValue && item.generated.Value == true)
                        {
                            Url = "http://"+item.url+".azurewebsites.net";
                              
                            <a href="@Url">@Url</a>
                        }
                        
                    </td>
                    <td>
                        @Html.ActionLink("Manage App", "ManageApp", new { id = item.Id }, new {@class="btn btn-primary"})
                    </td>
                </tr>
            }

        </table>


    }
    else
    {
        <div>
            <h1>
                No applications found
            </h1>
        </div>
    }
    <br />

    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

    @Html.PagedListPager(Model, page => Url.Action("Index",
            new { page, search = ViewBag.Search }))

<script src="@Url.Content("~/Scripts/plugins.js")"></script>
<script src="@Url.Content("~/Scripts/app.js")"></script>



